﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows;

namespace Faust.Andrew.MTG.Player.Converters
{
    public class TapStateToBoolConverter : IValueConverter
    {

        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (!(value is Shared.CardState))
            {
                return false;
            }

            Shared.CardState state = (Shared.CardState)value;
            if (state == Faust.Andrew.MTG.Player.Shared.CardState.Normal)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (!(value is bool?))
            {
                return Shared.CardState.Normal;
            }

            bool? tapped = (bool?)value;
            if (tapped == true)
            {
                return Shared.CardState.Tapped;
            }
            else
            {
                return Shared.CardState.Normal;
            }
        }

        #endregion
    }
}